package org.gc.webapp.action.sample;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.gc.common.vo.sample.SampleVO;
import org.gc.service.sample.SampleService;
import org.gc.webapp.action.BaseAction;
import org.gc.webapp.util.page.BasePageSO;
import org.gc.webapp.util.page.PageList;


public class SampleAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private SampleService sampleService;

	private Long id;
	private SampleVO vo;
	private PageList<SampleVO> pageList;



	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public SampleVO getVo() {
		return vo;
	}

	public void setVo(SampleVO vo) {
		this.vo = vo;
	}

	public PageList<SampleVO> getPageList() {
		return pageList;
	}

	public void setPageList(PageList<SampleVO> pageList) {
		this.pageList = pageList;
	}

	public SampleService getSampleService() {
		return sampleService;
	}

	public void setSampleService(SampleService sampleService) {
		this.sampleService = sampleService;
	}

	@Action("edit")
	public String edit() {
		if (id != null) {
			vo = sampleService.get(id);
		}
		return SUCCESS;
	}

	@Action(value = "save", results = { @Result(name = "input", location = "edit.jsp") })
	public String save() {
		if (vo != null) {
			sampleService.save(vo);
		} else {

		}
		return SUCCESS;
	}
	
	public void validateSave(){
		if (id != null) {
			vo = sampleService.get(id);
		}		
	}
	@Action("delete")
	public String delete() {
		if (id != null) {
			sampleService.remove(id);
		}
		return SUCCESS;
	}

	@Action("list")
	public String list() {
		pageList = sampleService.getPageList(new BasePageSO());
		// getRequest().setAttribute("addresses", addresses);
		return SUCCESS;
	}
}
